package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.AccLoanRevSubDao;
import com.fdb.efp.nls.service.domain.AccLoanRevSub;
import com.fdb.efp.nls.service.facade.AccLoanRevSubService;
import com.fdb.efp.nls.service.vo.AccLoanRevSubVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 自助循环贷款台帐子表				<p>
 * @author chenqm1
 * @date 2018-05-12
 */
@Service("accLoanRevSubService")
public class AccLoanRevSubServiceImpl implements AccLoanRevSubService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(AccLoanRevSubServiceImpl.class);

	@Autowired
	private AccLoanRevSubDao accLoanRevSubDao;
	
	/**
	 * 新增操作
	 */
	public int insertAccLoanRevSub(AccLoanRevSubVO accLoanRevSubVo) {
		logger.debug("当前新增数据为:"+ accLoanRevSubVo.toString());
		int num = 0;
		try {
			AccLoanRevSub accLoanRevSub = new AccLoanRevSub();
			beanCopy(accLoanRevSubVo, accLoanRevSub);
			num = accLoanRevSubDao.insertAccLoanRevSub(accLoanRevSub);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(AccLoanRevSubVO accLoanRevSubVo) {
		logger.debug("当前删除数据条件为:"+ accLoanRevSubVo);
		int num = 0;
		try {
			AccLoanRevSub accLoanRevSub = new AccLoanRevSub();
			beanCopy(accLoanRevSubVo, accLoanRevSub);
			num = accLoanRevSubDao.deleteByPk(accLoanRevSub);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ accLoanRevSubVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(AccLoanRevSubVO accLoanRevSubVo) {
		logger.debug("当前修改数据为:"+ accLoanRevSubVo.toString());
		int num = 0;
		try {
			AccLoanRevSub accLoanRevSub = new AccLoanRevSub();
			beanCopy(accLoanRevSubVo, accLoanRevSub);
			num = accLoanRevSubDao.updateByPk(accLoanRevSub);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ accLoanRevSubVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public AccLoanRevSubVO queryByPk(AccLoanRevSubVO accLoanRevSubVo) {
		
		logger.debug("当前查询参数信息为:"+ accLoanRevSubVo);
		try {
			AccLoanRevSub queryAccLoanRevSub = new AccLoanRevSub();
			beanCopy(accLoanRevSubVo, queryAccLoanRevSub);
			AccLoanRevSub queryRslAccLoanRevSub = accLoanRevSubDao.queryByPk(queryAccLoanRevSub);
			if (Objects.nonNull(queryRslAccLoanRevSub)) {
				AccLoanRevSubVO outAccLoanRevSubVo = beanCopy(queryRslAccLoanRevSub, new AccLoanRevSubVO());
				logger.debug("当前查询结果为:"+ outAccLoanRevSubVo.toString());
				return outAccLoanRevSubVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<AccLoanRevSubVO> queryAllOwner(AccLoanRevSubVO accLoanRevSubVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<AccLoanRevSubVO> list = null;
		try {
			List<AccLoanRevSub> accLoanRevSubs = accLoanRevSubDao.queryAllOwnerByPage(accLoanRevSubVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ accLoanRevSubs.size());
			pageSet(accLoanRevSubs, accLoanRevSubVo);
			list = (List<AccLoanRevSubVO>) beansCopy(accLoanRevSubs, AccLoanRevSubVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<AccLoanRevSubVO> queryAllCurrOrg(AccLoanRevSubVO accLoanRevSubVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<AccLoanRevSub> accLoanRevSubs = accLoanRevSubDao.queryAllCurrOrgByPage(accLoanRevSubVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+accLoanRevSubs.size());
		List<AccLoanRevSubVO> list = null;
		try {
			pageSet(accLoanRevSubs, accLoanRevSubVo);
			list = (List<AccLoanRevSubVO>) beansCopy(accLoanRevSubs, AccLoanRevSubVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<AccLoanRevSubVO> queryAllCurrDownOrg(AccLoanRevSubVO accLoanRevSubVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<AccLoanRevSub> accLoanRevSubs = accLoanRevSubDao.queryAllCurrDownOrgByPage(accLoanRevSubVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ accLoanRevSubs.size());
		List<AccLoanRevSubVO> list = null;
		try {
			pageSet(accLoanRevSubs, accLoanRevSubVo);
			list = (List<AccLoanRevSubVO>) beansCopy(accLoanRevSubs, AccLoanRevSubVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public List<AccLoanRevSubVO> queryByBillNo(AccLoanRevSubVO accLoanRevSubVo) {
		List<AccLoanRevSubVO> list = null;
		try {
			AccLoanRevSub accLoanRevSub = new AccLoanRevSub();
			beanCopy(accLoanRevSubVo, accLoanRevSub);
			List<AccLoanRevSub> accLoanRevSubs = accLoanRevSubDao.queryByBillNo(accLoanRevSub);
			list = (List<AccLoanRevSubVO>) beansCopy(accLoanRevSubs, AccLoanRevSubVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public int updateByBillNo(AccLoanRevSubVO accLoanRevSubVo) {
		logger.debug("当前修改数据为:"+ accLoanRevSubVo.toString());
		int num = 0;
		try {
			AccLoanRevSub accLoanRevSub = new AccLoanRevSub();
			beanCopy(accLoanRevSubVo, accLoanRevSub);
			num = accLoanRevSubDao.updateByBillNo(accLoanRevSub);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ accLoanRevSubVo +"修改的数据条数为"+ num);
		return num;
	}

}
